package cc.market.mapper;

import cc.market.entity.ProductCategory;
import cc.market.entity.ProductInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProductMapper {

    @Select("SELECT * FROM product_category")
    List<ProductCategory> getCategory();

    @Insert("INSERT INTO product_info " +
            "(title, user_id, category_id, price, cover_image, images, description, " +
            "post_type, province, city, create_time, update_time) " +
            "VALUES (#{title}, #{userId}, #{categoryId}, #{price}, #{coverImage}, #{images}, " +
            "#{description}, #{postType}, #{province}, #{city}, #{createTime}, #{updateTime})")
    void insert(ProductInfo productInfo);

    /**
     * 获取所有商品
     * @return
     */
    @Select("select * from product_info")
    List<ProductInfo> getAll();

    /**
     * 根据id获取商品
     * @return
     */
    @Select("SELECT * from product_info where category_id=#{categoryId}")
    List<ProductInfo> getByCatrgoryId( Integer categoryId);

    @Select("SELECT * from product_info where province=#{province} and city=#{city}")
    List<ProductInfo> getByLocation(String province, String city);

    @Select("SELECT * from product_info where id = #{id}")
    ProductInfo getById(Integer id);
}
